package com.javabi.unix.parser.ps;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class PsColumnSet {

	private final Map<String, Integer> columnIndexMap = new LinkedHashMap<String, Integer>();

	public void put(String column, int index) {
		if (column.isEmpty()) {
			throw new IllegalArgumentException("column is empty");
		}
		if (columnIndexMap.put(column, index) != null) {
			throw new IllegalStateException("duplicate column: '" + column + "'");
		}
	}

	public List<String> getColumnList() {
		return new ArrayList<String>(columnIndexMap.keySet());
	}

	public boolean contains(String column) {
		return columnIndexMap.get(column) != null;
	}

	public int indexOf(String column) {
		Integer index = columnIndexMap.get(column);
		if (index == null) {
			throw new IllegalArgumentException("not a column: '" + column + "'");
		}
		return index;
	}

	public int size() {
		return columnIndexMap.size();
	}

	public boolean isEmpty() {
		return columnIndexMap.isEmpty();
	}

	@Override
	public String toString() {
		return "PsColumnSet" + columnIndexMap.keySet();
	}

}
